package com.hainatong.shiphelper.mainhome.adapter;

import java.util.ArrayList;
import java.util.List;

import org.jetbrains.annotations.NotNull;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder;
import com.hainatong.shiphelper.R;
import com.hainatong.shiphelper.databinding.ItemStepviewBinding;
import com.hainatong.shiphelper.mainhome.entity.ProcessStepBean;
import com.hainatong.shiphelper.widget.timelineview.TimelineView;

import androidx.core.content.ContextCompat;

public class ProcessStepAdapter extends BaseQuickAdapter<ProcessStepBean, BaseDataBindingHolder<ItemStepviewBinding>>
{
    public static ProcessStepAdapter newInstance(String[] stepName,String[] stepData)
    {
        List<ProcessStepBean> setpList = new ArrayList<>();

        if( stepData!= null && stepData.length >0 )
        {
            for(int i = 0 ; i < stepData.length ;i++   )
            {
                ProcessStepBean model = new ProcessStepBean();
                model.setStatus(ProcessStepBean.StepStatus.ACTIVE );
                model.setStepName( stepName[i] );
                model.setData( stepData[i] );
                setpList.add( model );
            }
        }
        ProcessStepAdapter adapter = new ProcessStepAdapter();
        adapter.setList(setpList);
        return adapter;
    }

    public ProcessStepAdapter(List<ProcessStepBean> stepBeanList)
    {
        super(R.layout.item_stepview ,stepBeanList);
    }

    private ProcessStepAdapter()
    {
        super(R.layout.item_stepview);
    }

    @Override
    protected void convert(@NotNull BaseDataBindingHolder<ItemStepviewBinding> bindingHolder, ProcessStepBean stepBean)
    {
        ItemStepviewBinding binding = bindingHolder.getDataBinding();
        if( binding != null )
        {
            binding.textJob.setText( stepBean.getData() );
            binding.textStepName.setText(stepBean.getStepName());
            binding.timeline.setMarker(ContextCompat.getDrawable(getContext(),R.drawable.shape_oval_gray ), ContextCompat.getColor(getContext(),R.color.step_point_color));
            binding.timeline.setStartLineColor(ContextCompat.getColor(getContext(),R.color.step_point_color) , TimelineView.getTimeLineViewType( getItemPosition(stepBean) , getData().size() ));
            binding.timeline.setEndLineColor(ContextCompat.getColor(getContext(),R.color.step_point_color),TimelineView.getTimeLineViewType(getItemPosition(stepBean) , getData().size()) );
        }
    }
}
